package com.myself.springboot.springboot_study.controller;

import com.myself.springboot.springboot_study.exception.MyLoginException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class MyExceptionHandler{

    @ExceptionHandler(MyLoginException.class)
    public String handlerLoginException (Exception e, HttpServletRequest r) {
        Map<String, Object> map = new HashMap<>();
        r.setAttribute("javax.servlet.error.status_code",500);
        map.put("code","user.notexist");
        map.put("message","用户出错啦-----");
        r.setAttribute("ext",map);
        return "forward:/error";
    }
}
